package src;

import java.util.Vector;

public class MyDoc {

	int  hitId = 0;
	double currentScore = 0;
	Vector bitVector = null;
	QApair qap = null;
	String wholeSent = null;
	public void newMyDoc(int id, double weight, Vector b, String word){
		hitId = id;
		currentScore = weight;
		bitVector = b;
		wholeSent = word+" "+Double.toString(weight);
	}
	public void incrementCurrentScore(double weight){
		//currentScore += Math.pow(2, numOfBitSet())*weight;
		currentScore += weight;
	}
	
	public void normalize(){
		String question = qap.quest;
		String [] words = question.split(" ");
		//System.out.println(words.length);
		//System.out.println(currentScore);
		currentScore = currentScore/words.length;
		//System.out.println(currentScore);
	}
	public int numOfBitSet(){
		int count =0;
		for(int i=0; i< bitVector.size(); i++){
			if(isIndexSet(i)){
				count++;
			}
		}
		return count;
	}
	public void setQApair(QApair qa){
		qap = qa;
	}
	public boolean isIndexSet(int index){
		Bit b = (Bit)bitVector.get(index);
		if(b.isSet()){return true;}
		else {return false;}
	}
	
	public void setIndex(int index){
		Bit b = (Bit)bitVector.get(index);
		b.setBit();
	}
	public void addWord(String word, double weight){
		wholeSent = wholeSent+" "+word+" "+Double.toString(weight); 
	}
	public Vector initializeVector(int bitVectorSize, int varBitIndex){		
		Vector bitVector = new Vector();
		for(int i=0; i< bitVectorSize; i++){
			Bit b = new Bit();
			if(i== varBitIndex){
				 b.setBit();
			}
			else{
				b.resetBit();
			}
			bitVector.add(b);
		}
		return bitVector;
	}
	
	public boolean checkIfNotAdded(String word){
		String token[] = wholeSent.split(" ");
		for(int i=0; i< token.length; i++){
			if(token[i].equalsIgnoreCase(word)){
				//System.out.println(token[i]+">>>>>>>>>>>>>>");
				return false;
			}
		}
		return true;
	}
	
}
